<?php /* PROJECTS $Id: do_project_aed.php,v 1.11.10.4 2006/07/25 20:24:13 merlinyoda Exp $ */
$obj = new CTask();
$task_id = intval( dPgetParam( $_POST, 'task_id', 0 ) );
$salesAmount = dPgetParam( $_POST, 'sales_amount_input', 0 );
$salesAmount = currency2Double($salesAmount);
$obj->load($task_id);
$canEditSalesAmount = $perms->checkModuleItem( "taskfee", 'edit');
if(!$canEditSalesAmount) {
	$AppUI->setMsg( 'You do not have permission to edit task\' sales amount', UI_MSG_ERROR );
	$AppUI->redirect();
	exit;
}
if (isset($obj->task_quotation) && $obj->task_quotation > 0) {
	if ($salesAmount > 0) {
		$tax = $obj->task_vat;
		if ($tax > 0) {//including
			$task_vat_amount = $salesAmount - $salesAmount / ((100 + $tax) / 100);
			$salesAmount = $salesAmount / ((100 + $tax) / 100);
		} else { //excluding or non-vat
			$task_vat_amount = $salesAmount * -1 * $tax / 100;
		}
		$sql = "update tasks set task_fee = $salesAmount, task_vat_amount = $task_vat_amount where task_id = $task_id";
		db_exec($sql);
		$AppUI->setMsg( "Sales amount has been modified", UI_MSG_OK, true );
	} else {
		$AppUI->setMsg( "Ignore modify sales amount", UI_MSG_OK, true );
	}
} else {
	$AppUI->setMsg( 'You can not edit a task not yet link with a quotation', UI_MSG_ERROR );
	$AppUI->redirect();
	exit;
}
$AppUI->redirect();
?>